package com.koi.generator.utils;

import java.util.*;

/**
 * @author ･ᴗ･
 * @description [DataFilter]
 */
public class ListUtil {

    /**
     * @description [过滤两个List<String>集合不同的数据]
     * @author ･ᴗ･
     * @method fileterListString
     * @param list1
     * @param list2
     */
    public static List<String> getListFilter(List<String> list1, List<String> list2) {
        Set<String> set = new HashSet<>(list1);
        set.addAll(list2);

        Set<String> intersection = new HashSet<>(list1);
        intersection.retainAll(list2);

        set.removeAll(intersection);

        return new ArrayList<>(set);
    }

    /**
     * @description [获取list1跟list2相比不一样的数据]
     * @author ･ᴗ･
     * @method getList1Unlikeness
     * @param list1
     * @param list2
     */
    public static List<String> getListUnlikeness(List<String> list1, List<String> list2) {
        Set<String> set1 = new HashSet<>(list1);
        set1.removeAll(list2);
        return new ArrayList<>(set1);
    }

    /**
     * @description [获取两个List<String>交集]
     * @author ･ᴗ･
     * @method getIntersection
     * @param list1
     * @param list2
     */
    public static List<String> getListIntersection(List<String> list1, List<String> list2) {
        List<String> intersection = new ArrayList<>(list1);
        intersection.retainAll(list2);
        return intersection;
    }

    /**
     * @description [获取两个List<String>并集]
     * @author ･ᴗ･
     * @method getIntersection
     * @param list1
     * @param list2
     */
    public static List<String> getListUnion(List<String> list1, List<String> list2) {
        Set<String> unionSet = new HashSet<>(list1);
        unionSet.addAll(list2);
        return new ArrayList<>(unionSet);
    }

    public static void main(String[] args) {
        List<String> list1 = Arrays.asList("a", "b", "c", "d");
        List<String> list2 = Arrays.asList("b", "d", "e", "f");

        List<String> filterListString = getListFilter(list1, list2);
        List<String> missingInList1 = getListUnlikeness(list1, list2);
        List<String> missingInList2 = getListUnlikeness(list2, list1);
        List<String> listIntersection = getListIntersection(list1, list2);
        List<String> listUnion = getListUnion(list1, list2);
        System.out.println("两个集合所有不一致的元素: " + filterListString);
        System.out.println("list1跟list2不一样的元素: " + missingInList1);
        System.out.println("list2跟list1不一样的元素: " + missingInList2);
        System.out.println("交集: " + listIntersection);
        System.out.println("并集: " + listUnion);
    }

}
